package com.zhiyou100.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/test3")
public class MyController3 {
	@RequestMapping("/method1.do")
	public ModelAndView method1(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/WEB-INF/jsp/index.jsp");
		mav.addObject("message", "method1");
		return mav;
	}
	@RequestMapping("/method2.do")
	public ModelAndView method2(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/WEB-INF/jsp/a.jsp");
		mav.addObject("message", "method2");
		return mav;
	}
	/*
	 * 如果定义方法返回值类型为ModelAndView,返回modelAndView对象，是请求转发
	 * 如果定义方法返回值类型为String，返回的时候注意：forward请求转发，redirect表示请求重定向
	 * */
	@RequestMapping(value="/method3.do",method={RequestMethod.GET,RequestMethod.POST})
	public String method3(){
		return "forward:/WEB-INF/jsp/b.jsp";
	}
	@RequestMapping(value="/method4.do",method={RequestMethod.GET})
	public ModelAndView method4(){
		ModelAndView mav = new ModelAndView();
		mav.addObject("name", "张三");
		mav.addObject("age", 20);
		mav.setViewName("/test3/method3.do");
		return mav;
	}
}
